<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>随机排序</title>
<link rel="stylesheet" href="css/base.css" />
</head>
<body>
<div class="wrap">
	<h2 class="wrap-h2">javascript 排序，10组数据随机挑取5组！</h2>
	<div class="wrap-main">
		<p>排序前：a = 1,6,2,5,61,12,3,0,14,24,9,4,8,14,34,56</p>
		<div style="margin-top: 20px; line-height: 30px;">
			<p>排序后：</p>
			<p id="sortdomo"></p>
		</div>
	</div>
</div>
<script>
	window.onload = function ()
	{
		var oSortnew = document.getElementById("sortdomo");
		var a = [1,6,2,5,61,12,3,0,14,24,9,4,8,14,34,56,];
		console.log(a.length);
		var newdata = [];
		var count = 7;
		for(var i = count-1; i>=0; i--)
		{
			var ind = Math.floor(Math.random() * a.length);
			newdata.push(a[ind]);
			a.splice(ind,1);
		}
		console.log(newdata);
		
		newdata.sort(function(a,b){
			return a-b;
		});
		
		oSortnew.innerHTML = newdata;
	}
</script>
</body>
</html>
